﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DataObject.Database;
using DataObject.DataAccess;
using System.Web.UI.WebControls;

public class DropDownListHelper
{
    public static IList<ParameterEntity> Countries
    {
        get
        {
            if (HttpContext.Current.Cache["CountryList"] != null)
            {
                return (HttpContext.Current.Cache["CountryList"] as IList<ParameterEntity>);
            }

            var countries = ParameterDAO.CreateInstant().SelectListItem(null, "Country", string.Empty, string.Empty, null, true, new HashSet<string>());
            HttpContext.Current.Cache.Insert("CountryList", countries);

            return countries;
        }
    }

    public static IList<Route> Routes
    {
        get
        {
            if (HttpContext.Current.Cache["RouteList"] != null)
            {
                return (HttpContext.Current.Cache["RouteList"] as IList<Route>);
            }

            var routes = RouteDAO.CreateInstant().GetAllRoutes();
            HttpContext.Current.Cache.Insert("RouteList", routes);

            return routes;
        }
    }

    public static ListItem[] Currencies
    {
        get
        {
            if (HttpContext.Current.Cache["Currencies"] != null)
            {
                return (HttpContext.Current.Cache["Currencies"] as ListItem[]);
            }

            IList<ListItem> currencies = new List<ListItem>();
            Array temps = Enum.GetValues(typeof(CurrencyEnum));
            for (int i = 0; i < temps.Length; i++)
            {
                currencies.Add(new ListItem { Value = i.ToString(), Text = ((CurrencyEnum)temps.GetValue(i)).GetStringValue() });
            }
            HttpContext.Current.Cache.Insert("Currencies", currencies.ToArray<ListItem>());

            return currencies.ToArray<ListItem>();
        }
    }

    public static IList<string> PaymentMethods
    {
        get
        {
            if (HttpContext.Current.Cache["PaymentMethods"] != null)
            {
                return (HttpContext.Current.Cache["PaymentMethods"] as IList<string>);
            }

            IList<string> paymentMethods = new List<string>();
            foreach (var item in Enum.GetValues(typeof(PaidMethodEnum)))
            {
                paymentMethods.Add(((PaidMethodEnum)item).GetStringValue());
            }
            HttpContext.Current.Cache.Insert("PaymentMethods", paymentMethods);

            return paymentMethods;
        }
    }
}